<!--  -->
<template>
    <div>
        <!-- 表格 -->
        <el-table style="width: 100%" border :data="records">
            <el-table-column type="index" label="序号" width="80" align="center"></el-table-column>
            <el-table-column prop="skuName" label="名称" width="width"></el-table-column>
            <el-table-column prop="skuDesc" label="描述" width="width"></el-table-column>
            <el-table-column  label="默认图片" width="110">
                <template slot-scope="{row,$index}">
                    <img :src="row.skuDefaultImg" alt="" style="width: 80px; height: 80px;">
                </template>
            </el-table-column>
            <el-table-column prop="weight" label="重量" width="80"></el-table-column>
            <el-table-column prop="price" label="价格" width="80"></el-table-column>
            <el-table-column prop="prop" label="操作" width="width">
                <template slot-scope="{row,$index}">
                    <el-button type="success" icon="el-icon-sort-down" size="mini" v-if="row.isSale==0" @click="sale(row)"></el-button>
                    <el-button type="success" icon="el-icon-sort-up" size="mini" v-else @click="cancel(row)"></el-button>
                    <el-button type="primary" icon="el-icon-edit" size="mini" @click="update()"></el-button>
                    <el-button type="info" icon="el-icon-info" size="mini" @click="getSkuInfo(row)"></el-button>
                    <el-button type="danger" icon="el-icon-delete" size="mini"></el-button>
                </template>
            </el-table-column>
        </el-table>

        <!-- 分页  -->
        <el-pagination 
        style="text-align: center;" 
        @size-change="handleSizeChange"
        @current-change="getSkuList"
        :current-page="page"
         :page-sizes="[3, 5, 10]" 
         :page-size="limit"
         layout="prev,pager,next,jumper,->,sizes,total" :total="total">

        </el-pagination>

        <!-- 抽屉组件 -->
        
        <el-drawer
        title="我是标题"
        :visible.sync="drawer"
        :show-close="false"
        size="50%"
        :direction="direction">

        <el-row>
            <el-col :span="5">名称</el-col>
            <el-col :span="16">{{skuInfo.skuName}}</el-col>
        </el-row>
        <el-row>
            <el-col :span="5">描述</el-col>
            <el-col :span="16">{{skuInfo.skuDesc}}</el-col>
        </el-row>
        <el-row>
            <el-col :span="5">价格</el-col>
            <el-col :span="16">{{skuInfo.price}}</el-col>
        </el-row>
        <el-row>
            <el-col :span="5">平台属性</el-col>
            <el-col :span="16">
                <template>  
                    <el-tag type="success" v-for="(attr,index) in skuInfo.skuAttrValueList"  :key="attr.id" style="margin-right: 15px;">
                        {{attr.attrId}}-{{attr.valueId}}
                    </el-tag>
                </template>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="5">名称</el-col>
            <el-col :span="16">
                <template>
                <el-carousel indicator-position="outside">
                    <el-carousel-item v-for="item in skuInfo.skuImageList" :key="item">
                        <img :src="item.imgUrl"/>
                    </el-carousel-item>
                </el-carousel>
                </template>

            </el-col>
        </el-row>

        </el-drawer>

    </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';

export default {
    name: 'Sku',
    //import引入的组件需要注入到对象中才能使用
    components: {},
    data() {
        //这里存放数据
        return {
            page : 1,//代表当前页
            limit : 10,//代表每页展示多少条数据
            records:[],//存储sku列表的数据
            total:0,//存储分页器一共展示的数据
            skuInfo:{},
            drawer:false,//抽屉的显示与隐藏
            direction:'rtl',//抽屉打开的方式




        };
    },
   mounted(){
    this.getSkuList()
   },
    //方法集合
    methods: {
        //获取sku列表的方法
        async getSkuList(pages = 1){
            this.page = pages;
            //结构处默认的参数
            const {page,limit} = this;
            let result = await this.$API.sku.reqSkuList(page,limit);
            console.log(result);
            if(result.code==200){
                this.total = result.data.total;
                this.records= result.data.records;
            }
        },
        //修改当前页展示的多少参数
        handleSizeChange(limit){
            this.limit = limit;
            this.getSkuList();
        },
        async sale(row){
            let result = await this.$API.sku.reqSale(row.id);
            if(result.code == 200){
                row.isSale =1;
                this.$message({type:'success',message:'上架成功'});
            }
            this.getSkuList(this.page); 
        },
        async cancel(row){
            let result = await this.$API.sku.reqCancel(row.id);
            if(result.code == 200){
                row.isSale = 0;
                this.$message({type:'success',message:'下架成功'});
            }
            this.getSkuList(this.page);
        },
        update(){
            this.$message('程序员等待发了年终奖后开发');
        },
        async getSkuInfo(sku){
           let result =  await this.$API.sku.reqSkuById(sku.id);
            console.log(result);
            if(result.code == 200){
                this.skuInfo = result.data;
                this.drawer = true;
            }
        }

    },
}
</script>
<style lang='scss' scoped>
//@import url(); 引入公共css类
.el-row .el-col-5 {
        color:skyblue;
        font-size:18px;
        text-align:center;
    }
     .el-col {
        margin:10px 10px;            
     }
</style>
<style>
  /*  抽屉的样式和字体大小*/
  .el-carousel__item h3 {
    color: #475669;
    font-size: 18px;
    opacity: 0.75;
    line-height: 300px;
    margin: 0;
  }
  
  /* 轮播图的样式 */
  .el-carousel__item:nth-child(2n) {
    background-color: #99a9bf;
  }
  
  .el-carousel__item:nth-child(2n+1) {
    background-color: #d3dce6;
  }
  /* 轮播图底部小按钮的颜色 */
  .el-carousel__button{
    width:10px;
    height:10px;
    background:pink;
    border-radius: 50%;
  }
  
</style>